import { request } from "../../request/index.js"

Page({
    data: {
        goods: [],
        isFocus: false,
        inpValue: ''
    },
    TimeId: -1,
    handleInput(e) {
        const { value } = e.detail;
        if (!value.trim()) {
            this.setData({
                isFocus: false,
                goods: []
            })
            return;
        }
        this.setData({
            isFocus: true
        })
        clearTimeout(this.TimeId);
        this.TimeId = setTimeout(() => {
            this.qsearch(value)
        }, 1000)
    },
    handleFalse() {
        this.setData({
            isFocus: false,
            goods: [],
            inpValue: ''
        })
    },
    async qsearch(query) {
        const res = await request({ url: '/goods/qsearch', data: { query } })
        console.log(res);
        this.setData({
            goods: res.data.message
        })
    }
})